package com.teamcalendar.client.controller;

import com.teamcalendar.client.DBAdapter;

import android.app.Activity;
import android.database.Cursor;
import android.graphics.Color;
import android.graphics.Typeface;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListAdapter;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;

public class MessageAdapter extends SimpleCursorAdapter implements ListAdapter {
	Cursor cursor;
	Activity context;

	public MessageAdapter(Activity context, int textViewresourceId, Cursor cursor, String[] from, int[] to) {
		super(context, textViewresourceId, cursor, from, to);
		this.cursor = cursor;
		this.context = context;
	}
	
	public int getCount() {
		return cursor.getCount();
	}
	
	public View getView(int position, View convertView, ViewGroup parent) {
		this.cursor.moveToPosition(position);
		String messageText = this.cursor.getString(this.cursor.getColumnIndex(DBAdapter.KEY_MESSAGE));
		int read = this.cursor.getInt(this.cursor.getColumnIndex(DBAdapter.KEY_READ));
		
		TextView textView = new TextView(context);
		textView.setText(messageText);
		if (read == 0) {
			textView.setTypeface(Typeface.DEFAULT, Typeface.BOLD);			
		} else {
			textView.setTypeface(Typeface.DEFAULT, Typeface.NORMAL);
		}			
		textView.setTextColor(Color.BLACK);
		textView.setHeight(65);
		textView.setPadding(0, 0, 0, 14);
		textView.setWidth(320);
		return textView;
	}
}
